package br.com.rookgraph;

import java.util.Random;

public class GenerateGraph {
	
	public Graph generateWhit(int order, int per){
		Graph graph;
		do{
			graph = new Graph(order);
			
			for (int i = 1; i <= order; i++) {
				for (int j = 2; j <= order-1; j++) {
					if(i != j && lookMyluck(per)){
						graph.addEdge(i, j, 1);
					}
				}
			}
		
		}while(!isConnectGraph(graph));
		
		return graph;
	}
	
	private boolean isConnectGraph(Graph graph) {
		int order = graph.getOrder();
		int[] alcancaveis = graph.reached(new Random().nextInt(order)+1, new int[order]);
		return alcancaveis.length == order;
	}

	private boolean lookMyluck(int esperanca) {
		int random = new Random().nextInt(100);
		// System.out.println("\n"+random+"\n");
		return random < esperanca;
	}

	public static void main(String[] args) {
		Graph graph = new GenerateGraph().generateWhit(180, 2);
		graph.showMatix();
		
	}

}
